有个字符串. 我想取{# 和 #}中间的内容. 应该怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/28 09:46:03
有个字符串. 我想取{# 和 #}中间的内容. 应该怎么写?

string str="{#zhoulihgfdhg#}";
int i = str.IndexOf("{#")+"{#".Length;
int j = str.IndexOf("#}");
string str1 = str.Substring(i, j-i);

请参考: http://www.itpob.net/html/07/n-40407.html

string s = "asdfsd{#asdfsdfdsf#}dsafasdf";
s=s.Substring(s.IndexOf("{#") + 2, s.IndexOf("#}") - s.IndexOf("{#") - 2);
MessageBox.Show(s);

或者正则表达式{#([^#]*)#}